"ui";
ui.layout(
    <vertical padding="16">
        <text textSize="16sp" textColor="black" text="AndroidId"/>
        <input id="androidId" text=""/>
        <text textSize="16sp" textColor="black" text="Google AD_ID"/>
        <input id="gaid" text=""/>
        <button id="btnChangeAndroidId" text="更改AndroidId"/>
        <button id="btnChangeGoogleAdId" text="更改Google AD_ID"/>
        <button id="btnTimeZone" text="更换时区"/>
        <button id="close" text="关闭"/>
        <button id="check" text="json check"/>
        <button id="reboot" text="重启"/>
    </vertical>
);
ui.androidId.setText(device.getAndroidId());
ui.gaid.setText("");
//指定确定按钮点击时要执行的动作
ui.btnChangeAndroidId.click(function(){
    let path = '/data/system/users/0/settings_ssaid.xml';
    var result = shell(`rm -f ${path}`, true);
    ui.androidId.setText(device.getAndroidId());
    if(result.code == 0){
        toast('修改成功,请重启生效');
    }
    console.log(`result = `,result);
});

ui.btnChangeGoogleAdId.click(()=>{
    // let path = '/data/data/com.google.android.gms/shared_prefs/adid_settings.xml';
    // var result = shell(`rm -f ${path}`, true);
    console.log("fucking way");
});

ui.btnTimeZone.click(()=>{
    var result = shell(`am broadcast -a com.android.intent.action.LOCALE_CHANGED --es lang en --es country US`,true);
    console.log('result = ' , result);
});

ui.close.click(()=>{
    ui.finish();
});

ui.reboot.click(()=>{
    var receiver = new android.content.BroadcastReceiver({
        onReceive: function(context, intent) {
            var strI50 = intent.getStringExtra("i50");
            var strMediate = intent.getStringExtra("mediate");
            var strDevice = intent.getStringExtra("device");
            log("Received message: strI50 = " + strI50);
        }
    });
    
    var filter = new android.content.IntentFilter("SYN_AUTOHJS");
    context.registerReceiver(receiver, filter);
});

ui.check.click(()=>{
    // 配置文件路径，假设它位于项目根目录
    var configFilePath = "./config.json"; // 使用相对路径

    // 检查文件是否存在
    if (files.exists(configFilePath)) {
        var fileContent = files.read(configFilePath);
        
        // 解析 JSON 内容（假设配置文件是 JSON 格式）
        try {
            // var config = JSON.parse(fileContent);
            console.log("读取的配置内容:", fileContent);
        } catch (e) {
            console.log("解析 JSON 失败:", e);
        }
    } else {
        console.log("配置文件不存在");
    }
});